<template>
  <div class="article">
    <el-button type="primary" style="margin: 10px 0;float: left" @click="openDrawer('add')">添加新文章</el-button>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="title"
        label="标题"
        width="180">
      </el-table-column>
      <el-table-column
        prop="type_id"
        label="类型"
        width="180">
      </el-table-column>
      <el-table-column
        prop="create_time"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="sign"
        label="访问次数">
      </el-table-column>
      <el-table-column
        prop="original"
        label="是否原创">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <!--<el-button type="primary" icon="el-icon-edit" circle></el-button>-->
          <el-button type="primary" icon="el-icon-edit" circle @click="openDrawer('edit',scope.row.id)"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="deleteArticle(scope.row.id)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <draw-model ref="drowModel"/>
  </div>
</template>

<script>
  import DrawModel from "./component/DrawModel"

  export default {
    name: "Article",
    data() {
      return {
        tableData: []
      }
    },
    components: {
      DrawModel
    },
    created() {
      this.getArticleList()
    },
    methods: {
      openDrawer(data, id) {
        this.$refs.drowModel.openDrawerS(data, id);
      },
      //获取文章列表数据
      getArticleList() {

        //菜单列表
        this.getAxios("/article/all").then(res => {
          this.tableData = res.list;
        }).catch(err => {
          console.log(err);
        })
      },
      deleteArticle(id){
        this.deleteAxios('/article/deleteid',{id}).then(res=>{
          this.$message({
            message:res.msg,
            type:'success'
          });
          this.drawer = false;
          this.getArticleList();
        }).catch(err=>{
          console.log(err);
        })
      }
    }
  }
</script>

<style scoped>

</style>